﻿using System;
using System.Collections.Generic;
using FrankJie.Model;
using FrankJie.IDAL;
using FrankJie.Cache;

namespace FrankJie.BLL
{
    public class Manager
    {
        private readonly static IManager dal = DataAccess.CreateManager();

        /// <summary>
        /// 增加一个管理员
        /// </summary>
        /// <param name="model">管理员实体</param>
        /// <returns>返回管理员ID</returns>
        public static int Add(ManagerInfo managerInfo)
        {
            return dal.Add(managerInfo);
        }

        /// <summary>
        /// 更新一个管理员
        /// </summary>
        /// <param name="model">管理员实体</param>
        /// <returns>返回是否成功</returns>
        public static bool Update(ManagerInfo managerInfo)
        {
            return dal.Update(managerInfo);
        }

        /// <summary>
        /// 更新最后登录信息
        /// </summary>
        /// <param name="id">管理员ID</param>
        /// <param name="lastLogTime">最后登录时间</param>
        /// <param name="lastLogIp">最后登录IP</param>
        /// <returns>返回是否成功</returns>
        public static bool UpdateLastLog(int id, DateTime lastLogTime, string lastLogIp)
        {
            return dal.UpdateLastLog(id, lastLogTime, lastLogIp);
        }

        /// <summary>
        /// 管理员活动/禁用状态
        /// </summary>
        /// <param name="id">管理员ID</param>
        /// <param name="flag">true为活动状态 false为禁用状态</param>
        /// <returns>返回是否成功</returns>
        public static bool Enabled(int id, bool flag)
        {
            return Enabled(id, flag);
        }

        /// <summary>
        /// 删除一个管理员
        /// </summary>
        /// <param name="Id">管理员ID</param>
        /// <returns>返回是否成功</returns>
        public static bool Delete(int id)
        {
            return dal.Delete(id);
        }

        /// <summary>
        /// 管理员登录名密码检查
        /// </summary>
        /// <param name="loginName">登录名</param>
        /// <param name="passWord">密码</param>
        /// <param name="msg">返回消息</param>
        /// <returns>返回管理员实体</returns>
        public static ManagerInfo Login(string loginName, string passWord, out string msg)
        {
            return Login(loginName, passWord, out msg);
        }
    }
}
